/*
 * 练习6：比较两个对象引用的关系，稍作变换后再次比较。
 */
package chapter3_Operators;

/*
 * 因为这个练习复制过来的人家的答案，里面有一个类P和它的静态方法P.rintln();目前引入失败，正在研究中；
 * 后来干脆建了一个公共类库，在里面添加的类P和它的静态方法P.rintln()，以便今后都可随便引入
 */
import publicLibs.p; 

class Dog {
	String name;
	String says;
	void setName(String n) {
		name = n;
	}
	void setSays(String s) {
		says = s;
	}
	void showName() {
		p.rintln(name);
	}
	void speak() {
		p.rintln(says);
	}
}

public class E6_DogsCompare {
	public static void main(String[] args) {
		Dog spot = new Dog();
		spot.setName("Spot");
		spot.setSays("Ruff!");
		Dog scruffy = new Dog();
		scruffy.setName("Scruffy");
		scruffy.setSays("Wurf!");
		spot.showName();
		spot.speak();
		scruffy.showName(); 
		scruffy.speak();
		Dog butch = new Dog();
		butch.setName("Butch");
		butch.setSays("Hello!");
		butch.showName();
		butch.speak();
		p.rintln("Comparison: ");
		p.rintln("spot == butch: " + (spot == butch));
		p.rintln("spot.equals(butch): " + spot.equals(butch));
		p.rintln("butch.equals(spot): " + butch.equals(spot));
		p.rintln("Now assign: spot = butch");
		spot = butch;
		p.rintln("Compare again: ");
		p.rintln("spot == butch: " + (spot == butch));
		p.rintln("spot.equals(butch): " + spot.equals(butch));
		p.rintln("butch.equals(spot): " + butch.equals(spot));
		p.rintln("Spot: ");
		spot.showName();
		spot.speak();
		p.rintln("Butch: ");
		butch.showName();
		butch.speak();
			
	}
}